//
//  AppleTouchViewController.m
//  ClassManager
//
//  Created by mac on 2018/1/13.
//  Copyright © 2018年 GZX. All rights reserved.
//

#import "AppleTouchViewController.h"
#import "AppleTouchIDManager.h"

@interface AppleTouchViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UISwitch  *mySwitch;
@property(nonatomic,strong)UISwitch  *openSwitch;

@end

@implementation AppleTouchViewController

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleFullFit;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];


}
#pragma mark ---- UITableViewDelegate&&UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == 0) {
        cell.textLabel.text = @"是否支持TouchID";
        if (!self.mySwitch) {
            self.mySwitch = [[UISwitch alloc]initWithFrame:CGRectMake(kScreenWidth - 60,0, 100, 50)];
            self.mySwitch.userInteractionEnabled = NO;
            [cell.contentView addSubview:self.mySwitch];
        }
        self.mySwitch.on = [[[AppleTouchIDManager alloc]init]CheckCanSupportTouchID];
    }
    else if(indexPath.row == 1){
        cell.textLabel.text = @"是否启用了TouchID";
        if (!self.openSwitch) {
            self.openSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(kScreenWidth - 60, 0, 100, 50)];
            [self.openSwitch addTarget:self action:@selector(openTouchID:) forControlEvents:UIControlEventValueChanged];
            [cell.contentView addSubview:self.openSwitch];
        }
        self.openSwitch.on = [[[AppleTouchIDManager alloc]init]CheckCanOpenTouchID];
    }
    else if(indexPath.row == 2){
        cell.textLabel.text = @"验证Touch ID";
    }
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0,kScreenWidth, 0.1)];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0,kScreenWidth, 0.1)];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2) {
        [[[AppleTouchIDManager alloc]init]StratCheckTouchID:^(BOOL success, int code) {
            NSLog(@"xxxxxxxxx-----code = %d",code);
        }];
    }
}
-(void)openTouchID:(UISwitch *)sw{
    [[[AppleTouchIDManager alloc]init]StratCheckTouchID:^(BOOL success, int code) {
        NSLog(@"xxxxxxxxx-----code = %d",code);
        if (success) {
              [[[AppleTouchIDManager alloc]init]OpenTouchIDWith:sw.on];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
